<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <el-card class="search-card" shadow="hover">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="用户名" prop="nickName">
          <el-input
            v-model="queryParams.nickName"
            placeholder="请输入用户名"
            clearable
            prefix-icon="el-icon-user"
            style="width: 200px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="题目内容" prop="title">
          <el-input
            v-model="queryParams.title"
            placeholder="请输入题目内容"
            clearable
            prefix-icon="el-icon-search"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="isDeleted">
          <el-select v-model="queryParams.isDeleted" placeholder="请选择状态" clearable style="width: 120px">
            <el-option
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 操作区域 -->
    <el-card class="box-card" shadow="hover">
      <div slot="header" class="clearfix">
        <span class="card-title">错题列表</span>
        <div class="action-buttons">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['question:wrongquestion:export']"
          >导出</el-button>
          <el-button
            :type="showDeleted ? 'warning' : 'info'"
            plain
            icon="el-icon-delete"
            size="mini"
            @click="toggleRecycleBin"
          >{{ showDeleted ? '返回列表' : '回收站' }}</el-button>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </div>
      </div>

      <!-- 表格区域 -->
      <el-table
        v-loading="loading"
        :data="wrongquestionList"
        border
        stripe
        highlight-current-row
      >
        <el-table-column label="错题ID" align="center" prop="id" width="80" />
        <el-table-column label="用户名" align="center" prop="sysUser.nickName" width="120" />
        <el-table-column label="题目内容" align="left" prop="dtQuestion.title" :show-overflow-tooltip="true" min-width="300">
          <template slot-scope="scope">
            <div class="question-content" v-html="scope.row.dtQuestion.title"></div>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="isDeleted" width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.isDeleted"/>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { listWrongquestion } from "@/api/question/wrongquestion";

export default {
  name: "Wrongquestion",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 错题表格数据
      wrongquestionList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        questionId: null,
        isDeleted: '0'
      },
      showDeleted: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询错题列表 */
    getList() {
      this.loading = true;
      listWrongquestion(this.queryParams).then(response => {
        this.wrongquestionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.isDeleted = this.showDeleted ? '1' : '0';
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('question/wrongquestion/export', {
        ...this.queryParams
      }, `wrong_question_${new Date().getTime()}.xlsx`)
    },
    toggleRecycleBin() {
      this.showDeleted = !this.showDeleted;
      this.queryParams.isDeleted = this.showDeleted ? '1' : '0';
      this.handleQuery();
    },
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认永久删除该错题记录？该操作不可恢复！').then(function() {
        return delWrongQuestion(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>

<style scoped>
.search-card {
  margin-bottom: 16px;
  border-radius: 4px;
}

.box-card {
  margin-bottom: 16px;
  border-radius: 4px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2f3d;
}

.action-buttons {
  float: right;
}

.question-content {
  padding: 8px 12px;
  line-height: 1.6;
  text-align: left;
  background-color: #f5f7fa;
  border-radius: 4px;
  min-height: 24px;
}

/* 移除段落标签的默认边距 */
.question-content :deep(p) {
  margin: 0;
  padding: 0;
}

.el-card {
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08) !important;
}

.el-card :deep(.el-card__header) {
  padding: 12px 20px;
  border-bottom: 1px solid #ebeef5;
  background-color: #fafafa;
}

.el-table {
  margin: 8px 0;
}

.el-table :deep(th) {
  background-color: #f5f7fa !important;
  color: #606266;
  font-weight: 600;
}

.el-table :deep(td) {
  padding: 8px 0;
}

.el-tag {
  padding: 0 8px;
  height: 24px;
  line-height: 22px;
}

/* 表格hover效果 */
.el-table :deep(tbody tr:hover) td {
  background-color: #f5f7fa !important;
}

/* 输入框图标颜色 */
.el-input :deep(.el-input__icon) {
  color: #909399;
}

/* 表单项间距 */
.el-form-item {
  margin-bottom: 16px;
}
</style>
